package com.dailyblue.java.project.bookstore.controller;

import com.dailyblue.java.project.bookstore.service.BookService;
import com.dailyblue.java.project.bookstore.util.JsonResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/book")
public class BookController {
    @Resource
    private BookService bookService;

    @GetMapping("/{num}")
    public JsonResult find(@PathVariable int num) {
        return bookService.findNewBook(num);
    }

    @GetMapping("/{itemId}/{page}")
    public JsonResult find(@PathVariable("itemId") String itemId, @PathVariable("page") int page) {
        return bookService.findBookByItem(itemId, page);
    }

    @GetMapping("/search")
    public JsonResult find(String itemId, @RequestParam(defaultValue = "1") int page, String bookName) {
        return bookService.findSearchByBookNameAndItem(itemId, page, bookName);
    }
}
